﻿using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using SXFramWork.Core;
using SXFramWork.Model;
using SXFramWork.Service;

namespace SXFramWork.API.Controllers.Admin
{
    /// <summary>
    /// 部门管理
    /// </summary>
    public class SysOrganizeController : WebController
    {
        private readonly ISysOrganizeService _orgService;
        public SysOrganizeController(ISysOrganizeService sysOrganizeService)
        {
            _orgService = sysOrganizeService;
        }
        /// <summary>
        /// 查询树形结构
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Power("部门树形")]
        public Task<IApiResult> GetTree()
        {
           return _orgService.GetTree();
        }
        /// <summary>
        /// 查询列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        [Menu("部门管理")]
        public async Task<IApiResult> List([FromQuery]OrgQueryModel model)
        {
            return await _orgService.Query(model);
        }
        /// <summary>
        /// 新增部门
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [Power("新增")]
        public async Task<IApiResult> Add([FromBody] OrgAddModel model)
        {
            return await _orgService.Add(model);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        [Power("删除")]
        public async Task<IApiResult> Delete([FromBody]string id)
        {
            return await _orgService.Delete(id);
        }
        /// <summary>
        /// 查询单个
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [Power("查询")]
        public async Task<IApiResult> Get([FromQuery] string id)
        {
            return await _orgService.GetById(id);
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [Power("更新")]
        public async Task<IApiResult> Update([FromBody] OrgUpdateModel model)
        {
            return await _orgService.Update(model);
        }
    }
}